import { defineStore } from 'pinia'
import { getInfoAPI } from '@/api/index.js'
import { useMenuStore } from '../menu/index.js'

export const useUserGlobalStore = defineStore('globalUser', {
    state: () => {
        return {
            userInfo: '',
            permissions: [],
            roles: [],
        }
    },
    getters: {
        getCollapse(state) {

        }
    },

    actions: {
        async getClobalUserInfo() {
            if (!this.usseraInfo) {
                let res = await getInfoAPI()
                this.userInfo = res.userInfoVo
                this.permissions = res.permissions
                this.roles = res.roles
                await useMenuStore().loadAuthRouters()
            }
        },
        reset() {
            this.userInfo = ''
            this.permissions = []
            this.roles = []
        }
    },
    persist: {
        enabled: true,
        strategies: [{
            storage: localStorage,
            key: 'userStore'
        }]
    }
})